#include<iostream>
#include<cstdio>
using namespace std;

struct node{
  int data;
  int next;
}a[2000001];

int main(){
  int x,y,n,m,head=-1,k=0;
  int t;
  cin>>n;
  cin>>t;
  a[k].data = t;
  a[k].next = -1;
  head=k;
  k++;
  for(int i = 0;i < n - 1;i++){
    cin>>t;
    a[k].data = t;
    a[k].next = head;
    head = k;
    k++;
  }
  cin>>m;
  for(int i = 0;i < m;i++){
    cin>>x>>y;
    a[k].data = y;
    a[k].next = a[x-1].next;
    a[x-1].next = k;
    k++;
  }
  for(int i = head;i != -1;i = a[i].next){
    cout<<a[i].data<<" ";
  }
  return 0;
}
